import React from 'react';
import PropTypes from 'prop-types';

import ChildOne from './child-a'
import ChildTwo from './child-b'

export default class Container extends React.Component {
    constructor(props) {
        super(props);
        this.state = { value: '' }
    }
    changeValue = value => {
        this.setState({ value })
    }
    //向子组件传递的值和方法
    getChildContext() {
        return {
            value: this.state.value,
            changeValue: this.changeValue
        }
    }
    render() {
        return (
            <div>
                <ChildOne />
                <div>-------------------------</div>
                <ChildTwo />
            </div>
        )
    }
}
//定义传递类型
Container.childContextTypes = {
    value: PropTypes.string,
    changeValue: PropTypes.func
}